package cn.edu.ecut.proxy3;

public class Test2 {

	public static void main(String[] args) throws Exception {
		
		final Object target = new Smartisan();
		
		// 用 匿名内部类 继承 具体类 并重写其方法
		final Object proxy = new Smartisan() {
			@Override
			public String produce() {
				if( target instanceof Smartisan ) {
					Smartisan s = (Smartisan) target ;
					System.out.println( "start" );
					String value = s.produce() ; // 指派给 target 执行
					System.out.println( "end" );
					return value ;
				}
				return null ;
			}
		};
		
		
		if( proxy instanceof Smartisan ) {
			Smartisan s = (Smartisan) proxy ;
			s.produce();
		}

	}

}
